#include "shopdialogitems.h"
#include <QPainter>
#include "shopdialog.h"

ShopDialogBg::ShopDialogBg(GameDialog *d, QPixmap bg)
    :GameDialogItem(d), _bg(bg)
{
}


QRectF ShopDialogBg::boundingRect() const{
    return QRectF(-_bg.width()/2, -_bg.height()/2, _bg.width(), _bg.height());
}


void ShopDialogBg::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->drawPixmap(-_bg.width()/2, -_bg.height()/2, _bg);
}


//shop dialog owner
ShopDialogOwner::ShopDialogOwner(GameDialog *d, QPixmap owner)
    :GameDialogItem(d), _owner(owner)
{
}


QRectF ShopDialogOwner::boundingRect() const{
    return QRectF(-_owner.width()/2, -_owner.height()/2, _owner.width(), _owner.height());
}


void ShopDialogOwner::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->drawPixmap(-_owner.width()/2, -_owner.height()/2, _owner);
}

//shop text area
ShopDialogText::ShopDialogText(GameDialog *d)
    :GameDialogItem(d)
{
}


QRectF ShopDialogText::boundingRect() const{
    return QRectF(-WIDTH/2, -HEIGHT/2, WIDTH, HEIGHT);
}


void ShopDialogText::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    QPainterPath p;
    p.addRoundRect(boundingRect(), 0.5);
    painter->drawPath(p);
    painter->fillPath(p, QColor(255,255,255,125));
}



//shop dialog button

ShopDialogButton::ShopDialogButton(GameDialog *d)
    :GameDialogButton(d)
{

}


QRectF ShopDialogButton::boundingRect() const{
    return QRectF(-WIDTH/2, -HEIGHT/2, WIDTH, HEIGHT);
}




//exit button
ShopDialogExitButton::ShopDialogExitButton(GameDialog *d)
    :ShopDialogButton(d)
{

}

void ShopDialogExitButton::mousePressEvent(QGraphicsSceneMouseEvent *event){
    getDialog()->hideStarted();
}


void ShopDialogExitButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->fillRect(boundingRect(), Qt::red);
    painter->drawText(boundingRect(), Qt::AlignCenter | Qt::AlignHCenter, "Exit");
}
//herbalist button
ShopDialogHerbalistButton::ShopDialogHerbalistButton(GameDialog *d)
    :ShopDialogButton(d)
{

}

void ShopDialogHerbalistButton::mousePressEvent(QGraphicsSceneMouseEvent *event){
    ((HerbalistShopDialog*)getDialog())->takeTaoItem();
}

void ShopDialogHerbalistButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->fillRect(boundingRect(), Qt::red);
    painter->drawText(boundingRect(), Qt::AlignCenter | Qt::AlignHCenter, "Take");
}


//sorcerer button
ShopDialogSorcererButton::ShopDialogSorcererButton(GameDialog *d)
    :ShopDialogButton(d)
{

}

void ShopDialogSorcererButton::mousePressEvent(QGraphicsSceneMouseEvent *event){
    ((SorcererShopDialog*)getDialog())->discardGhost();
}

void ShopDialogSorcererButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->fillRect(boundingRect(), Qt::red);
    painter->drawText(boundingRect(), Qt::AlignCenter | Qt::AlignHCenter, "Discard");
}
//pavilion button
ShopDialogPavilionButton::ShopDialogPavilionButton(GameDialog *d)
    :ShopDialogButton(d)
{

}

void ShopDialogPavilionButton::mousePressEvent(QGraphicsSceneMouseEvent *event){
    ((PavilionShopDialog*)getDialog())->moveGhostAndPlayer();
}

void ShopDialogPavilionButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->fillRect(boundingRect(), Qt::red);
    painter->drawText(boundingRect(), Qt::AlignCenter | Qt::AlignHCenter, "Move");
}


//cemetery button
ShopDialogCemeteryButton::ShopDialogCemeteryButton(GameDialog *d)
    :ShopDialogButton(d)
{

}

void ShopDialogCemeteryButton::mousePressEvent(QGraphicsSceneMouseEvent *event){
    ((CemeteryShopDialog*)getDialog())->faceupVillage();
}

void ShopDialogCemeteryButton::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    painter->fillRect(boundingRect(), Qt::red);
    painter->drawText(boundingRect(), Qt::AlignCenter | Qt::AlignHCenter, "Recover");
}
